﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Board.Models
{
    public class Tools
    {

        public static bool UserIsLogedIn
        {
            get { return HttpContext.Current.Request.IsAuthenticated && !string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name); }
        }

        public static WebUser CurrentUser
        {
            get
            {
                if (HttpContext.Current.Session["CurrentUser"] == null)
                {
                    string username = HttpContext.Current.User.Identity.Name;
                    if (!string.IsNullOrEmpty(username))
                    {
                        HttpContext.Current.Session["CurrentUser"] = new WebUser(username);
                    }
                    else
                    {
                        return new WebUser();
                    }
                }
                return (WebUser)HttpContext.Current.Session["CurrentUser"];
            }

        }

        public static HashSet<Site> AllSites
        {
            get
            {
                using (DbEntities db = new DbEntities())
                {
                    return new HashSet<Site>(from s in db.t_AllUnitBed
                                             select new Site() { SiteId = s.SiteID });
                }
            }
        } 

        public static HashSet<Unit> AllUnit
        {
            get
            {
                using (DbEntities db = new DbEntities())
                {
                    return new HashSet<Unit>(from u in db.t_AllUnitBed
                                             select new Unit() { SiteId = u.SiteID, UnitId = u.UnitID});
                }
            }
        } 






        public static void UpdateCurrentUser()
        {
            string username = HttpContext.Current.User.Identity.Name;
            if (!string.IsNullOrEmpty(username))
            {
                HttpContext.Current.Session["CurrentUser"] = new WebUser(username);
            }
        }

        public static string REFRESH_METHOD_CURRENT_PAGE = "CurrentPage";
        public static string REFRESH_METHOD_CURRENT_UNIT = "CurrentUnit";
        public static string REFRESH_METHOD_CURRENT_SITE = "CurrentSite";
        public static string REFRESH_METHOD_ALL = "AllBeds";
        public static string REFRESH_METHOD_NO = "NoRefresh";

        public static string DELIVERY_OTHER_SVD = "SVD";
        public static string DELIVERY_OTHER_EMERG_CS = "ECS";
        public static string DELIVERY_OTHER_Vac = "Vac";
        public static string DELIVERY_OTHER_RA = "RA";
        public static string DELIVERY_OTHER_Forceps = "FCP";
        public static string DELIVERY_OTHER_Other = "OTH";
        public static string DELIVERY_OTHER_Elect_CS = "ELE";

        public static List<string>  RefreshMethodList
        {
            get
            {
                return new List<string>(){REFRESH_METHOD_NO, REFRESH_METHOD_CURRENT_PAGE, REFRESH_METHOD_CURRENT_UNIT,REFRESH_METHOD_CURRENT_SITE, REFRESH_METHOD_ALL};
            }
        }






    }
}